home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb / sprite / RCS / valops.c,v < prev    next >
Encoding:
Text File  |  1991-07-03  |  34.4 KB  |  1,333 lines

  1. head     1.3;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.3
  10. date     91.07.02.22.55.57;  author jhh;  state Exp;
  11. branches ;
  12. next     1.2;
  13.  
  14. 1.2
  15. date     90.12.09.22.36.07;  author rab;  state Exp;
  16. branches ;
  17. next     1.1;
  18.  
  19. 1.1
  20. date     90.11.16.14.44.20;  author rab;  state Exp;
  21. branches ;
  22. next     ;
  23.  
  24.  
  25. desc
  26. @@
  27.  
  28.  
  29. 1.3
  30. log
  31. @changes due to diffs for Mips support
  32. @
  33. text
  34. @/* Perform non-arithmetic operations on values, for GDB.
  35.    Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc.
  36.  
  37. This file is part of GDB.
  38.  
  39. GDB is free software; you can redistribute it and/or modify
  40. it under the terms of the GNU General Public License as published by
  41. the Free Software Foundation; either version 1, or (at your option)
  42. any later version.
  43.  
  44. GDB is distributed in the hope that it will be useful,
  45. but WITHOUT ANY WARRANTY; without even the implied warranty of
  46. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  47. GNU General Public License for more details.
  48.  
  49. You should have received a copy of the GNU General Public License
  50. along with GDB; see the file COPYING.  If not, write to
  51. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  52.  
  53. #include "stdio.h"
  54. #include "defs.h"
  55. #include "param.h"
  56. #include "symtab.h"
  57. #include "value.h"
  58. #include "frame.h"
  59. #include "inferior.h"
  60.  
  61. /* Cast value ARG2 to type TYPE and return as a value.
  62.    More general than a C cast: accepts any two types of the same length,
  63.    and if ARG2 is an lvalue it can be cast into anything at all.  */
  64.  
  65. value
  66. value_cast (type, arg2)
  67.      struct type *type;
  68.      register value arg2;
  69. {
  70.   register enum type_code code1;
  71.   register enum type_code code2;
  72.   register int scalar;
  73.  
  74.   /* Coerce arrays but not enums.  Enums will work as-is
  75.      and coercing them would cause an infinite recursion.  */
  76.   if (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_ENUM)
  77.     COERCE_ARRAY (arg2);
  78.  
  79.   code1 = TYPE_CODE (type);
  80.   code2 = TYPE_CODE (VALUE_TYPE (arg2));
  81.   scalar = (code2 == TYPE_CODE_INT || code2 == TYPE_CODE_FLT
  82.         || code2 == TYPE_CODE_ENUM);
  83.  
  84.   if (code1 == TYPE_CODE_FLT && scalar)
  85.     return value_from_double (type, value_as_double (arg2));
  86.   else if ((code1 == TYPE_CODE_INT || code1 == TYPE_CODE_ENUM)
  87.        && (scalar || code2 == TYPE_CODE_PTR))
  88.     return value_from_long (type, value_as_long (arg2));
  89.   else if (TYPE_LENGTH (type) == TYPE_LENGTH (VALUE_TYPE (arg2)))
  90.     {
  91.       VALUE_TYPE (arg2) = type;
  92.       return arg2;
  93.     }
  94.   else if (VALUE_LVAL (arg2) == lval_memory)
  95.     {
  96.       return value_at (type, VALUE_ADDRESS (arg2) + VALUE_OFFSET (arg2));
  97.     }
  98.   else
  99.     error ("Invalid cast.");
  100. }
  101.  
  102. /* Create a value of type TYPE that is zero, and return it.  */
  103.  
  104. value
  105. value_zero (type, lv)
  106.      struct type *type;
  107.      enum lval_type lv;
  108. {
  109.   register value val = allocate_value (type);
  110.  
  111.   bzero (VALUE_CONTENTS (val), TYPE_LENGTH (type));
  112.   VALUE_LVAL (val) = lv;
  113.  
  114.   return val;
  115. }
  116.  
  117. /* Return the value with a specified type located at specified address.  */
  118.  
  119. value
  120. value_at (type, addr)
  121.      struct type *type;
  122.      CORE_ADDR addr;
  123. {
  124.   register value val = allocate_value (type);
  125.   int temp;
  126.  
  127.   temp = read_memory (addr, VALUE_CONTENTS (val), TYPE_LENGTH (type));
  128.   if (temp)
  129.     {
  130.       if (have_inferior_p ())
  131.     print_sys_errmsg ("ptrace", temp);
  132.       /* Actually, address between addr and addr + len was out of bounds. */
  133.       error ("Cannot read memory: address 0x%x out of bounds.", addr);
  134.     }
  135.  
  136.   VALUE_LVAL (val) = lval_memory;
  137.   VALUE_ADDRESS (val) = addr;
  138.  
  139.   return val;
  140. }
  141.  
  142. /* Store the contents of FROMVAL into the location of TOVAL.
  143.    Return a new value with the location of TOVAL and contents of FROMVAL.  */
  144.  
  145. value
  146. value_assign (toval, fromval)
  147.      register value toval, fromval;
  148. {
  149.   register struct type *type = VALUE_TYPE (toval);
  150.   register value val;
  151.   char raw_buffer[MAX_REGISTER_RAW_SIZE];
  152.   char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
  153.   int use_buffer = 0;
  154.  
  155.   extern CORE_ADDR find_saved_register ();
  156.  
  157.   COERCE_ARRAY (fromval);
  158.  
  159.   if (VALUE_LVAL (toval) != lval_internalvar)
  160.     fromval = value_cast (type, fromval);
  161.  
  162.   /* If TOVAL is a special machine register requiring conversion
  163.      of program values to a special raw format,
  164.      convert FROMVAL's contents now, with result in `raw_buffer',
  165.      and set USE_BUFFER to the number of bytes to write.  */
  166.  
  167.   if (VALUE_REGNO (toval) >= 0
  168.       && REGISTER_CONVERTIBLE (VALUE_REGNO (toval)))
  169.     {
  170.       int regno = VALUE_REGNO (toval);
  171.       if (VALUE_TYPE (fromval) != REGISTER_VIRTUAL_TYPE (regno))
  172.     fromval = value_cast (REGISTER_VIRTUAL_TYPE (regno), fromval);
  173.       bcopy (VALUE_CONTENTS (fromval), virtual_buffer,
  174.          REGISTER_VIRTUAL_SIZE (regno));
  175.       REGISTER_CONVERT_TO_RAW (regno, virtual_buffer, raw_buffer);
  176.       use_buffer = REGISTER_RAW_SIZE (regno);
  177.     }
  178.  
  179.   switch (VALUE_LVAL (toval))
  180.     {
  181.     case lval_internalvar:
  182.       set_internalvar (VALUE_INTERNALVAR (toval), fromval);
  183.       break;
  184.  
  185.     case lval_internalvar_component:
  186.       set_internalvar_component (VALUE_INTERNALVAR (toval),
  187.                  VALUE_OFFSET (toval),
  188.                  VALUE_BITPOS (toval),
  189.                  VALUE_BITSIZE (toval),
  190.                  fromval);
  191.       break;
  192.  
  193.     case lval_memory:
  194.       if (VALUE_BITSIZE (toval))
  195.     {
  196.       int val;
  197.       read_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  198.                &val, sizeof val);
  199.       modify_field (&val, (int) value_as_long (fromval),
  200.             VALUE_BITPOS (toval), VALUE_BITSIZE (toval));
  201.       write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  202.             &val, sizeof val);
  203.     }
  204.       else if (use_buffer)
  205.     write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  206.               raw_buffer, use_buffer);
  207.       else
  208.     write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  209.               VALUE_CONTENTS (fromval), TYPE_LENGTH (type));
  210.       break;
  211.  
  212.     case lval_register:
  213.       if (VALUE_BITSIZE (toval))
  214.     {
  215.       int val;
  216.  
  217.       read_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  218.                    &val, sizeof val);
  219.       modify_field (&val, (int) value_as_long (fromval),
  220.             VALUE_BITPOS (toval), VALUE_BITSIZE (toval));
  221.       write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  222.                 &val, sizeof val);
  223.     }
  224.       else if (use_buffer)
  225.     write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  226.                   raw_buffer, use_buffer);
  227.       else
  228.     write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  229.                   VALUE_CONTENTS (fromval), TYPE_LENGTH (type));
  230.       break;
  231.  
  232.     case lval_reg_frame_relative:
  233.       {
  234.     /* value is stored in a series of registers in the frame
  235.        specified by the structure.  Copy that value out, modify
  236.        it, and copy it back in.  */
  237.     int amount_to_copy = (VALUE_BITSIZE (toval) ? 1 : TYPE_LENGTH (type));
  238.     int reg_size = REGISTER_RAW_SIZE (VALUE_FRAME_REGNUM (toval));
  239.     int byte_offset = VALUE_OFFSET (toval) % reg_size;
  240.     int reg_offset = VALUE_OFFSET (toval) / reg_size;
  241.     int amount_copied;
  242.     char *buffer = (char *) alloca (amount_to_copy);
  243.     int regno;
  244.     FRAME frame;
  245.     CORE_ADDR addr;
  246.  
  247.     /* Figure out which frame this is in currently.  */
  248.     for (frame = get_current_frame ();
  249.          frame && FRAME_FP (frame) != VALUE_FRAME (toval);
  250.          frame = get_prev_frame (frame))
  251.       ;
  252.  
  253.     if (!frame)
  254.       error ("Value being assigned to is no longer active.");
  255.  
  256.     amount_to_copy += (reg_size - amount_to_copy % reg_size);
  257.  
  258.     /* Copy it out.  */
  259.     for ((regno = VALUE_FRAME_REGNUM (toval) + reg_offset,
  260.           amount_copied = 0);
  261.          amount_copied < amount_to_copy;
  262.          amount_copied += reg_size, regno++)
  263.       {
  264.         addr = find_saved_register (frame, regno);
  265.         if (addr == 0)
  266.           read_register_bytes (REGISTER_BYTE (regno),
  267.                    buffer + amount_copied,
  268.                    reg_size);
  269.         else
  270.           read_memory (addr, buffer + amount_copied, reg_size);
  271.       }
  272.  
  273.     /* Modify what needs to be modified.  */
  274.     if (VALUE_BITSIZE (toval))
  275.       modify_field (buffer + byte_offset,
  276.             (int) value_as_long (fromval),
  277.             VALUE_BITPOS (toval), VALUE_BITSIZE (toval));
  278.     else if (use_buffer)
  279.       bcopy (raw_buffer, buffer + byte_offset, use_buffer);
  280.     else
  281.       bcopy (VALUE_CONTENTS (fromval), buffer + byte_offset,
  282.          TYPE_LENGTH (type));
  283.  
  284.     /* Copy it back.  */
  285.     for ((regno = VALUE_FRAME_REGNUM (toval) + reg_offset,
  286.           amount_copied = 0);
  287.          amount_copied < amount_to_copy;
  288.          amount_copied += reg_size, regno++)
  289.       {
  290.         addr = find_saved_register (frame, regno);
  291.         if (addr == 0)
  292.           write_register_bytes (REGISTER_BYTE (regno),
  293.                     buffer + amount_copied,
  294.                     reg_size);
  295.         else
  296.           write_memory (addr, buffer + amount_copied, reg_size);
  297.       }
  298.       }
  299.       break;
  300.     
  301.  
  302.     default:
  303.       error ("Left side of = operation is not an lvalue.");
  304.     }
  305.  
  306.   /* Return a value just like TOVAL except with the contents of FROMVAL
  307.      (except in the case of the type if TOVAL is an internalvar).  */
  308.  
  309.   if (VALUE_LVAL (toval) == lval_internalvar
  310.       || VALUE_LVAL (toval) == lval_internalvar_component)
  311.     {
  312.       type = VALUE_TYPE (fromval);
  313.     }
  314.  
  315.   val = allocate_value (type);
  316.   bcopy (toval, val, VALUE_CONTENTS (val) - (char *) val);
  317.   bcopy (VALUE_CONTENTS (fromval), VALUE_CONTENTS (val), TYPE_LENGTH (type));
  318.   VALUE_TYPE (val) = type;
  319.   
  320.   return val;
  321. }
  322.  
  323. /* Extend a value VAL to COUNT repetitions of its type.  */
  324.  
  325. value
  326. value_repeat (arg1, count)
  327.      value arg1;
  328.      int count;
  329. {
  330.   register value val;
  331.  
  332.   if (VALUE_LVAL (arg1) != lval_memory)
  333.     error ("Only values in memory can be extended with '@@'.");
  334.   if (count < 1)
  335.     error ("Invalid number %d of repetitions.", count);
  336.  
  337.   val = allocate_repeat_value (VALUE_TYPE (arg1), count);
  338.  
  339.   read_memory (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1),
  340.            VALUE_CONTENTS (val),
  341.            TYPE_LENGTH (VALUE_TYPE (val)) * count);
  342.   VALUE_LVAL (val) = lval_memory;
  343.   VALUE_ADDRESS (val) = VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1);
  344.  
  345.   return val;
  346. }
  347.  
  348. value
  349. value_of_variable (var)
  350.      struct symbol *var;
  351. {
  352.   return read_var_value (var, (FRAME) 0);
  353. }
  354.  
  355. /* Given a value which is an array, return a value which is
  356.    a pointer to its first element.  */
  357.  
  358. value
  359. value_coerce_array (arg1)
  360.      value arg1;
  361. {
  362.   register struct type *type;
  363.   register value val;
  364.  
  365.   if (VALUE_LVAL (arg1) != lval_memory)
  366.     error ("Attempt to take address of value not located in memory.");
  367.  
  368.   /* Get type of elements.  */
  369.   if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_ARRAY)
  370.     type = TYPE_TARGET_TYPE (VALUE_TYPE (arg1));
  371.   else
  372.     /* A phony array made by value_repeat.
  373.        Its type is the type of the elements, not an array type.  */
  374.     type = VALUE_TYPE (arg1);
  375.  
  376.   /* Get the type of the result.  */
  377.   type = lookup_pointer_type (type);
  378.   val = value_from_long (builtin_type_long,
  379.                (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
  380.   VALUE_TYPE (val) = type;
  381.   return val;
  382. }
  383.  
  384. /* Return a pointer value for the object for which ARG1 is the contents.  */
  385.  
  386. value
  387. value_addr (arg1)
  388.      value arg1;
  389. {
  390.   register struct type *type;
  391.   register value val, arg1_coerced;
  392.  
  393.   /* Taking the address of an array is really a no-op
  394.      once the array is coerced to a pointer to its first element.  */
  395.   arg1_coerced = arg1;
  396.   COERCE_ARRAY (arg1_coerced);
  397.   if (arg1 != arg1_coerced)
  398.     return arg1_coerced;
  399.  
  400.   if (VALUE_LVAL (arg1) != lval_memory)
  401.     error ("Attempt to take address of value not located in memory.");
  402.  
  403.   /* Get the type of the result.  */
  404.   type = lookup_pointer_type (VALUE_TYPE (arg1));
  405.   val = value_from_long (builtin_type_long,
  406.         (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
  407.   VALUE_TYPE (val) = type;
  408.   return val;
  409. }
  410.  
  411. /* Given a value of a pointer type, apply the C unary * operator to it.  */
  412.  
  413. value
  414. value_ind (arg1)
  415.      value arg1;
  416. {
  417.   /* Must do this before COERCE_ARRAY, otherwise an infinite loop
  418.      will result */
  419.   if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_REF)
  420.     return value_at (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)),
  421.              (CORE_ADDR) value_as_long (arg1));
  422.  
  423.   COERCE_ARRAY (arg1);
  424.  
  425.   if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_MEMBER)
  426.     error ("not implemented: member types in value_ind");
  427.  
  428.   /* Allow * on an integer so we can cast it to whatever we want.
  429.      This returns an int, which seems like the most C-like thing
  430.      to do.  "long long" variables are rare enough that
  431.      BUILTIN_TYPE_LONGEST would seem to be a mistake.  */
  432.   if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_INT)
  433.     return value_at (builtin_type_int,
  434.              (CORE_ADDR) value_as_long (arg1));
  435.   else if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR)
  436.     return value_at (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)),
  437.              (CORE_ADDR) value_as_long (arg1));
  438.   else if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_REF)
  439.     return value_at (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)),
  440.              (CORE_ADDR) value_as_long (arg1));
  441.   error ("Attempt to take contents of a non-pointer value.");
  442. }
  443.  
  444. /* Pushing small parts of stack frames.  */
  445.  
  446. /* Push one word (the size of object that a register holds).  */
  447.  
  448. CORE_ADDR
  449. push_word (sp, buffer)
  450.      CORE_ADDR sp;
  451.      REGISTER_TYPE buffer;
  452. {
  453.   register int len = sizeof (REGISTER_TYPE);
  454.  
  455. #if 1 INNER_THAN 2
  456.   sp -= len;
  457.   write_memory (sp, &buffer, len);
  458. #else /* stack grows upward */
  459.   write_memory (sp, &buffer, len);
  460.   sp += len;
  461. #endif /* stack grows upward */
  462.  
  463.   return sp;
  464. }
  465.  
  466. /* Push LEN bytes with data at BUFFER.  */
  467.  
  468. CORE_ADDR
  469. push_bytes (sp, buffer, len)
  470.      CORE_ADDR sp;
  471.      char *buffer;
  472.      int len;
  473. {
  474. #if 1 INNER_THAN 2
  475.   sp -= len;
  476.   write_memory (sp, buffer, len);
  477. #else /* stack grows upward */
  478.   write_memory (sp, buffer, len);
  479.   sp += len;
  480. #endif /* stack grows upward */
  481.  
  482.   return sp;
  483. }
  484.  
  485. /* Push onto the stack the specified value VALUE.  */
  486.  
  487. CORE_ADDR
  488. value_push (sp, arg)
  489.      register CORE_ADDR sp;
  490.      value arg;
  491. {
  492.   register int len = TYPE_LENGTH (VALUE_TYPE (arg));
  493.  
  494. #if 1 INNER_THAN 2
  495.   sp -= len;
  496.   write_memory (sp, VALUE_CONTENTS (arg), len);
  497. #else /* stack grows upward */
  498.   write_memory (sp, VALUE_CONTENTS (arg), len);
  499.   sp += len;
  500. #endif /* stack grows upward */
  501.  
  502.   return sp;
  503. }
  504.  
  505. /* Perform the standard coercions that are specified
  506.    for arguments to be passed to C functions.  */
  507.  
  508. value
  509. value_arg_coerce (arg)
  510.      value arg;
  511. {
  512.   register struct type *type;
  513.  
  514.   COERCE_ENUM (arg);
  515.  
  516.   type = VALUE_TYPE (arg);
  517.  
  518.   if (TYPE_CODE (type) == TYPE_CODE_INT
  519.       && TYPE_LENGTH (type) < sizeof (int))
  520.     return value_cast (builtin_type_int, arg);
  521.  
  522.   if (type == builtin_type_float)
  523.     return value_cast (builtin_type_double, arg);
  524.  
  525.   return arg;
  526. }
  527.  
  528. /* Push the value ARG, first coercing it as an argument
  529.    to a C function.  */
  530.  
  531. CORE_ADDR
  532. value_arg_push (sp, arg)
  533.      register CORE_ADDR sp;
  534.      value arg;
  535. {
  536.   return value_push (sp, value_arg_coerce (arg));
  537. }
  538.  
  539. /* Perform a function call in the inferior.
  540.    ARGS is a vector of values of arguments (NARGS of them).
  541.    FUNCTION is a value, the function to be called.
  542.    Returns a value representing what the function returned.
  543.    May fail to return, if a breakpoint or signal is hit
  544.    during the execution of the function.  */
  545.  
  546. value
  547. call_function (function, nargs, args)
  548.      value function;
  549.      int nargs;
  550.      value *args;
  551. {
  552.   register CORE_ADDR sp;
  553.   register int i;
  554.   CORE_ADDR start_sp;
  555.   static REGISTER_TYPE dummy[] = CALL_DUMMY;
  556.   REGISTER_TYPE dummy1[sizeof dummy / sizeof (REGISTER_TYPE)];
  557.   CORE_ADDR old_sp;
  558.   struct type *value_type;
  559.   unsigned char struct_return;
  560.   CORE_ADDR struct_addr;
  561.   struct inferior_status inf_status;
  562.   struct cleanup *old_chain;
  563.  
  564.   if (!have_inferior_p ())
  565.     error ("Cannot invoke functions if the inferior is not running.");
  566.  
  567. #ifndef KGDB  
  568.   save_inferior_status (&inf_status, 1);
  569.   old_chain = make_cleanup (restore_inferior_status, &inf_status);
  570.  
  571.   /* PUSH_DUMMY_FRAME is responsible for saving the inferior registers
  572.      (and POP_FRAME for restoring them).  (At least on most machines)
  573.      they are saved on the stack in the inferior.  */
  574.   PUSH_DUMMY_FRAME;
  575.  
  576.   old_sp = sp = read_register (SP_REGNUM);
  577.  
  578. #if 1 INNER_THAN 2        /* Stack grows down */
  579.   sp -= sizeof dummy;
  580.   start_sp = sp;
  581. #else                /* Stack grows up */
  582.   start_sp = sp;
  583.   sp += sizeof dummy;
  584. #endif
  585. #endif
  586.  
  587.   {
  588.     register CORE_ADDR funaddr;
  589.     register struct type *ftype = VALUE_TYPE (function);
  590.     register enum type_code code = TYPE_CODE (ftype);
  591.  
  592.     /* If it's a member function, just look at the function
  593.        part of it.  */
  594.  
  595.     /* Determine address to call.  */
  596.     if (code == TYPE_CODE_FUNC || code == TYPE_CODE_METHOD)
  597.       {
  598.     funaddr = VALUE_ADDRESS (function);
  599.     value_type = TYPE_TARGET_TYPE (ftype);
  600.       }
  601.     else if (code == TYPE_CODE_PTR)
  602.       {
  603.     funaddr = value_as_long (function);
  604.     if (TYPE_CODE (TYPE_TARGET_TYPE (ftype)) == TYPE_CODE_FUNC
  605.         || TYPE_CODE (TYPE_TARGET_TYPE (ftype)) == TYPE_CODE_METHOD)
  606.       value_type = TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (ftype));
  607.     else
  608.       value_type = builtin_type_int;
  609.       }
  610.     else if (code == TYPE_CODE_INT)
  611.       {
  612.     /* Handle the case of functions lacking debugging info.
  613.        Their values are characters since their addresses are char */
  614.     if (TYPE_LENGTH (ftype) == 1)
  615.       funaddr = value_as_long (value_addr (function));
  616.     else
  617.       /* Handle integer used as address of a function.  */
  618.       funaddr = value_as_long (function);
  619.  
  620.     value_type = builtin_type_int;
  621.       }
  622.     else
  623.       error ("Invalid data type for function to be called.");
  624. #ifdef KGDB
  625.  /* Create a call sequence customized for this function
  626.     and the number of arguments for it.  */
  627.    if (remote_debugging) {
  628.     int    val;
  629.     char argBuffer[512];
  630.     char *ap;
  631.     ap = argBuffer;
  632.     for (i = 0; i < nargs; i++) {
  633.             value arg = value_arg_coerce (args[i]);
  634.             int len = TYPE_LENGTH (VALUE_TYPE (arg));
  635.            if (ap + len > &(argBuffer[512]) )
  636.             break;
  637.            bcopy(VALUE_CONTENTS (arg),ap,len);
  638.            ap += len;
  639.     }
  640.     val = call_remote_function(funaddr,nargs,ap - argBuffer,argBuffer);
  641.     return value_from_long (builtin_type_int, val);
  642.    }
  643. #endif    
  644.  
  645.     /* Are we returning a value using a structure return or a normal
  646.        value return? */
  647.  
  648.     struct_return = using_struct_return (function, funaddr, value_type);
  649.  
  650.     /* Create a call sequence customized for this function
  651.        and the number of arguments for it.  */
  652.     bcopy (dummy, dummy1, sizeof dummy);
  653.     FIX_CALL_DUMMY (dummy1, start_sp, funaddr, nargs, value_type);
  654.   }
  655.  
  656. #ifndef CANNOT_EXECUTE_STACK
  657.   write_memory (start_sp, dummy1, sizeof dummy);
  658.  
  659. #else
  660.   /* Convex Unix prohibits executing in the stack segment. */
  661.   /* Hope there is empty room at the top of the text segment. */
  662.   {
  663.     extern CORE_ADDR text_end;
  664.     static checked = 0;
  665.     if (!checked)
  666.       for (start_sp = text_end - sizeof dummy; start_sp < text_end; ++start_sp)
  667.     if (read_memory_integer (start_sp, 1) != 0)
  668.       error ("text segment full -- no place to put call");
  669.     checked = 1;
  670.     sp = old_sp;
  671.     start_sp = text_end - sizeof dummy;
  672.     write_memory (start_sp, dummy1, sizeof dummy);
  673.   }
  674. #endif /* CANNOT_EXECUTE_STACK */
  675. #ifdef STACK_ALIGN
  676.   /* If stack grows down, we must leave a hole at the top. */
  677.   {
  678.     int len = 0;
  679.  
  680.     /* Reserve space for the return structure to be written on the
  681.        stack, if necessary */
  682.  
  683.     if (struct_return)
  684.       len += TYPE_LENGTH (value_type);
  685.     
  686.     for (i = nargs - 1; i >= 0; i--)
  687.       len += TYPE_LENGTH (VALUE_TYPE (value_arg_coerce (args[i])));
  688. #ifdef CALL_DUMMY_STACK_ADJUST
  689.     len += CALL_DUMMY_STACK_ADJUST;
  690. #endif
  691. #if 1 INNER_THAN 2
  692.     sp -= STACK_ALIGN (len) - len;
  693. #else
  694.     sp += STACK_ALIGN (len) - len;
  695. #endif
  696.   }
  697. #endif /* STACK_ALIGN */
  698.  
  699.     /* Reserve space for the return structure to be written on the
  700.        stack, if necessary */
  701.  
  702.     if (struct_return)
  703.       {
  704. #if 1 INNER_THAN 2
  705.     sp -= TYPE_LENGTH (value_type);
  706.     struct_addr = sp;
  707. #else
  708.     struct_addr = sp;
  709.     sp += TYPE_LENGTH (value_type);
  710. #endif
  711.       }
  712.     
  713. #ifdef PUSH_ARGUMENTS
  714.   PUSH_ARGUMENTS(nargs, args, sp, struct_return, struct_addr);
  715. #else /* !PUSH_ARGUMENTS */
  716.   for (i = nargs - 1; i >= 0; i--)
  717.     sp = value_arg_push (sp, args[i]);
  718.  
  719. #ifdef CALL_DUMMY_STACK_ADJUST
  720. #if 1 INNER_THAN 2
  721.   sp -= CALL_DUMMY_STACK_ADJUST;
  722. #else
  723.   sp += CALL_DUMMY_STACK_ADJUST;
  724. #endif
  725. #endif /* CALL_DUMMY_STACK_ADJUST */
  726.  
  727.   /* Store the address at which the structure is supposed to be
  728.      written.  Note that this (and the code which reserved the space
  729.      above) assumes that gcc was used to compile this function.  Since
  730.      it doesn't cost us anything but space and if the function is pcc
  731.      it will ignore this value, we will make that assumption.
  732.  
  733.      Also note that on some machines (like the sparc) pcc uses this
  734.      convention in a slightly twisted way also.  */
  735.  
  736.   if (struct_return)
  737.     STORE_STRUCT_RETURN (struct_addr, sp);
  738. #endif /* !PUSH_ARGUMENTS */
  739.  
  740.   /* Write the stack pointer.  This is here because the statement above
  741.      might fool with it */
  742.   write_register (SP_REGNUM, sp);
  743.  
  744.   /* Figure out the value returned by the function.  */
  745.   {
  746.     char retbuf[REGISTER_BYTES];
  747.  
  748.     /* Execute the stack dummy routine, calling FUNCTION.
  749.        When it is done, discard the empty frame
  750.        after storing the contents of all regs into retbuf.  */
  751.     run_stack_dummy (start_sp + CALL_DUMMY_START_OFFSET, retbuf);
  752.  
  753.     do_cleanups (old_chain);
  754.  
  755.     return value_being_returned (value_type, retbuf, struct_return);
  756.   }
  757. }
  758.  
  759. /* Create a value for a string constant:
  760.    Call the function malloc in the inferior to get space for it,
  761.    then copy the data into that space
  762.    and then return the address with type char *.
  763.    PTR points to the string constant data; LEN is number of characters.  */
  764.  
  765. value
  766. value_string (ptr, len)
  767.      char *ptr;
  768.      int len;
  769. {
  770.   register value val;
  771.   register struct symbol *sym;
  772.   value blocklen;
  773.   register char *copy = (char *) alloca (len + 1);
  774.   char *i = ptr;
  775.   register char *o = copy, *ibeg = ptr;
  776.   register int c;
  777.  
  778.   /* Copy the string into COPY, processing escapes.
  779.      We could not conveniently process them in expread
  780.      because the string there wants to be a substring of the input.  */
  781.  
  782.   while (i - ibeg < len)
  783.     {
  784.       c = *i++;
  785.       if (c == '\\')
  786.     {
  787.       c = parse_escape (&i);
  788.       if (c == -1)
  789.         continue;
  790.     }
  791.       *o++ = c;
  792.     }
  793.   *o = 0;
  794.  
  795.   /* Get the length of the string after escapes are processed.  */
  796.  
  797.   len = o - copy;
  798.  
  799.   /* Find the address of malloc in the inferior.  */
  800.  
  801.   sym = lookup_symbol ("malloc", 0, VAR_NAMESPACE, 0);
  802.   if (sym != 0)
  803.     {
  804.       if (SYMBOL_CLASS (sym) != LOC_BLOCK)
  805.     error ("\"malloc\" exists in this program but is not a function.");
  806.       val = value_of_variable (sym);
  807.     }
  808.   else
  809.     {
  810.       register int i;
  811.       for (i = 0; i < misc_function_count; i++)
  812.     if (!strcmp (misc_function_vector[i].name, "malloc"))
  813.       break;
  814.       if (i < misc_function_count)
  815.     val = value_from_long (builtin_type_long,
  816.                  (LONGEST) misc_function_vector[i].address);
  817.       else
  818.     error ("String constants require the program to have a function \"malloc\".");
  819.     }
  820.  
  821.   blocklen = value_from_long (builtin_type_int, (LONGEST) (len + 1));
  822.   val = call_function (val, 1, &blocklen);
  823.   if (value_zerop (val))
  824.     error ("No memory available for string constant.");
  825.   write_memory ((CORE_ADDR) value_as_long (val), copy, len + 1);
  826.   VALUE_TYPE (val) = lookup_pointer_type (builtin_type_char);
  827.   return val;
  828. }
  829.  
  830. /* Given ARG1, a value of type (pointer to a)* structure/union,
  831.    extract the component named NAME from the ultimate target structure/union
  832.    and return it as a value with its appropriate type.
  833.    ERR is used in the error message if ARG1's type is wrong.
  834.  
  835.    C++: ARGS is a list of argument types to aid in the selection of
  836.    an appropriate method. Also, handle derived types.
  837.  
  838.    STATIC_MEMFUNCP, if non-NULL, points to a caller-supplied location
  839.    where the truthvalue of whether the function that was resolved was
  840.    a static member function or not.
  841.  
  842.    ERR is an error message to be printed in case the field is not found.  */
  843.  
  844. value
  845. value_struct_elt (arg1, args, name, static_memfuncp, err)
  846.      register value arg1, *args;
  847.      char *name;
  848.      int *static_memfuncp;
  849.      char *err;
  850. {
  851.   register struct type *t;
  852.   register int i;
  853.   int found = 0;
  854.  
  855.   struct type *baseclass;
  856.  
  857.   COERCE_ARRAY (arg1);
  858.  
  859.   t = VALUE_TYPE (arg1);
  860.  
  861.   /* Follow pointers until we get to a non-pointer.  */
  862.  
  863.   while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)
  864.     {
  865.       arg1 = value_ind (arg1);
  866.       COERCE_ARRAY (arg1);
  867.       t = VALUE_TYPE (arg1);
  868.     }
  869.  
  870.   if (TYPE_CODE (t) == TYPE_CODE_MEMBER)
  871.     error ("not implemented: member type in value_struct_elt");
  872.  
  873.   if (TYPE_CODE (t) != TYPE_CODE_STRUCT
  874.       && TYPE_CODE (t) != TYPE_CODE_UNION)
  875.     error ("Attempt to extract a component of a value that is not a %s.", err);
  876.  
  877.   baseclass = t;
  878.  
  879.   /* Assume it's not, unless we see that it is.  */
  880.   if (static_memfuncp)
  881.     *static_memfuncp =0;
  882.  
  883.   if (!args)
  884.     {
  885.       /* if there are no arguments ...do this...  */
  886.  
  887.       /* Try as a variable first, because if we succeed, there
  888.      is less work to be done.  */
  889.       while (t)
  890.     {
  891.       for (i = TYPE_NFIELDS (t) - 1; i >= 0; i--)
  892.         {
  893.           char *t_field_name = TYPE_FIELD_NAME (t, i);
  894.           if (t_field_name && !strcmp (t_field_name, name))
  895.         {
  896.           found = 1;
  897.           break;
  898.         }
  899.         }
  900.  
  901.       if (i >= 0)
  902.         return TYPE_FIELD_STATIC (t, i)
  903.           ? value_static_field (t, name, i) : value_field (arg1, i);
  904.  
  905.       if (TYPE_N_BASECLASSES (t) == 0)
  906.         break;
  907.  
  908.       t = TYPE_BASECLASS (t, 1);
  909.       VALUE_TYPE (arg1) = t; /* side effect! */
  910.     }
  911.  
  912.       /* C++: If it was not found as a data field, then try to
  913.          return it as a pointer to a method.  */
  914.       t = baseclass;
  915.       VALUE_TYPE (arg1) = t;    /* side effect! */
  916.  
  917.       if (destructor_name_p (name, t))
  918.     error ("use `info method' command to print out value of destructor");
  919.  
  920.       while (t)
  921.     {
  922.       for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; --i)
  923.         {
  924.           if (! strcmp (TYPE_FN_FIELDLIST_NAME (t, i), name))
  925.         {
  926.           error ("use `info method' command to print value of method \"%s\"", name);
  927.         }
  928.         }
  929.  
  930.       if (TYPE_N_BASECLASSES (t) == 0)
  931.         break;
  932.  
  933.       t = TYPE_BASECLASS (t, 1);
  934.     }
  935.  
  936.       if (found == 0)
  937.     error ("There is no field named %s.", name);
  938.       return 0;
  939.     }
  940.  
  941.   if (destructor_name_p (name, t))
  942.     {
  943.       if (!args[1])
  944.     {
  945.       /* destructors are a special case.  */
  946.       return (value)value_fn_field (arg1, 0,
  947.                     TYPE_FN_FIELDLIST_LENGTH (t, 0));
  948.     }
  949.       else
  950.     {
  951.       error ("destructor should not have any argument");
  952.     }
  953.     }
  954.  
  955.   /*   This following loop is for methods with arguments.  */
  956.   while (t)
  957.     {
  958.       /* Look up as method first, because that is where we
  959.      expect to find it first.  */
  960.       for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; i--)
  961.     {
  962.       struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
  963.  
  964.       if (!strcmp (TYPE_FN_FIELDLIST_NAME (t, i), name))
  965.         {
  966.           int j;
  967.           struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
  968.  
  969.           found = 1;
  970.           for (j = TYPE_FN_FIELDLIST_LENGTH (t, i) - 1; j >= 0; --j)
  971.         if (!typecmp (TYPE_FN_FIELD_STATIC_P (f, j),
  972.                   TYPE_FN_FIELD_ARGS (f, j), args))
  973.           {
  974.             if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
  975.               return (value)value_virtual_fn_field (arg1, f, j, t);
  976.             if (TYPE_FN_FIELD_STATIC_P (f, j) && static_memfuncp)
  977.               *static_memfuncp = 1;
  978.             return (value)value_fn_field (arg1, i, j);
  979.           }
  980.         }
  981.     }
  982.  
  983.       if (TYPE_N_BASECLASSES (t) == 0)
  984.     break;
  985.       
  986.       t = TYPE_BASECLASS (t, 1);
  987.       VALUE_TYPE (arg1) = t;    /* side effect! */
  988.     }
  989.  
  990.   if (found)
  991.     {
  992.       error ("Structure method %s not defined for arglist.", name);
  993.       return 0;
  994.     }
  995.   else
  996.     {
  997.       /* See if user tried to invoke data as function */
  998.       t = baseclass;
  999.       while (t)
  1000.     {
  1001.       for (i = TYPE_NFIELDS (t) - 1; i >= 0; i--)
  1002.         {
  1003.           char *t_field_name = TYPE_FIELD_NAME (t, i);
  1004.           if (t_field_name && !strcmp (t_field_name, name))
  1005.         {
  1006.           found = 1;
  1007.           break;
  1008.         }
  1009.         }
  1010.  
  1011.       if (i >= 0)
  1012.         return TYPE_FIELD_STATIC (t, i)
  1013.           ? value_static_field (t, name, i) : value_field (arg1, i);
  1014.  
  1015.       if (TYPE_N_BASECLASSES (t) == 0)
  1016.         break;
  1017.  
  1018.       t = TYPE_BASECLASS (t, 1);
  1019.       VALUE_TYPE (arg1) = t; /* side effect! */
  1020.     }
  1021.       error ("Structure has no component named %s.", name);
  1022.     }
  1023. }
  1024.  
  1025. /* C++: return 1 is NAME is a legitimate name for the destructor
  1026.    of type TYPE.  If TYPE does not have a destructor, or
  1027.    if NAME is inappropriate for TYPE, an error is signaled.  */
  1028. int
  1029. destructor_name_p (name, type)
  1030.      char *name;
  1031.      struct type *type;
  1032. {
  1033.   /* destructors are a special case.  */
  1034.   char *dname = TYPE_NAME (type);
  1035.  
  1036.   if (name[0] == '~')
  1037.     {
  1038.       if (! TYPE_HAS_DESTRUCTOR (type))
  1039.     error ("type `%s' does not have destructor defined",
  1040.            TYPE_NAME (type));
  1041.       /* Skip past the "struct " at the front.  */
  1042.       while (*dname++ != ' ') ;
  1043.       if (strcmp (dname, name+1))
  1044.     error ("destructor specification error");
  1045.       else
  1046.     return 1;
  1047.     }
  1048.   return 0;
  1049. }
  1050.  
  1051. /* C++: Given ARG1, a value of type (pointer to a)* structure/union,
  1052.    return 1 if the component named NAME from the ultimate
  1053.    target structure/union is defined, otherwise, return 0.  */
  1054.  
  1055. int
  1056. check_field (arg1, name)
  1057.      register value arg1;
  1058.      char *name;
  1059. {
  1060.   register struct type *t;
  1061.   register int i;
  1062.   int found = 0;
  1063.  
  1064.   struct type *baseclass;
  1065.  
  1066.   COERCE_ARRAY (arg1);
  1067.  
  1068.   t = VALUE_TYPE (arg1);
  1069.  
  1070.   /* Follow pointers until we get to a non-pointer.  */
  1071.  
  1072.   while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)
  1073.     t = TYPE_TARGET_TYPE (t);
  1074.  
  1075.   if (TYPE_CODE (t) == TYPE_CODE_MEMBER)
  1076.     error ("not implemented: member type in check_field");
  1077.  
  1078.   if (TYPE_CODE (t) != TYPE_CODE_STRUCT
  1079.       && TYPE_CODE (t) != TYPE_CODE_UNION)
  1080.     error ("Internal error: `this' is not an aggregate");
  1081.  
  1082.   baseclass = t;
  1083.  
  1084.   while (t)
  1085.     {
  1086.       for (i = TYPE_NFIELDS (t) - 1; i >= 0; i--)
  1087.     {
  1088.       char *t_field_name = TYPE_FIELD_NAME (t, i);
  1089.       if (t_field_name && !strcmp (t_field_name, name))
  1090.         {
  1091.           return 1;
  1092.         }
  1093.     }
  1094.       if (TYPE_N_BASECLASSES (t) == 0)
  1095.     break;
  1096.  
  1097.       t = TYPE_BASECLASS (t, 1);
  1098.     }
  1099.  
  1100.   /* C++: If it was not found as a data field, then try to
  1101.      return it as a pointer to a method.  */
  1102.   t = baseclass;
  1103.   VALUE_TYPE (arg1) = t;    /* side effect! */
  1104.  
  1105.   /* Destructors are a special case.  */
  1106.   if (destructor_name_p (name, t))
  1107.     return 1;
  1108.  
  1109.   while (t)
  1110.     {
  1111.       for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; --i)
  1112.     {
  1113.       if (!strcmp (TYPE_FN_FIELDLIST_NAME (t, i), name))
  1114.         return 1;
  1115.     }
  1116.  
  1117.       if (TYPE_N_BASECLASSES (t) == 0)
  1118.     break;
  1119.  
  1120.       t = TYPE_BASECLASS (t, 1);
  1121.     }
  1122.   return 0;
  1123. }
  1124.  
  1125. /* C++: Given an aggregate type DOMAIN, and a member name NAME,
  1126.    return the address of this member as a pointer to member
  1127.    type.  If INTYPE is non-null, then it will be the type
  1128.    of the member we are looking for.  This will help us resolve
  1129.    pointers to member functions.  */
  1130.  
  1131. value
  1132. value_struct_elt_for_address (domain, intype, name)
  1133.      struct type *domain, *intype;
  1134.      char *name;
  1135. {
  1136.   register struct type *t = domain;
  1137.   register int i;
  1138.   int found = 0;
  1139.   value v;
  1140.  
  1141.   struct type *baseclass;
  1142.  
  1143.   if (TYPE_CODE (t) != TYPE_CODE_STRUCT
  1144.       && TYPE_CODE (t) != TYPE_CODE_UNION)
  1145.     error ("Internal error: non-aggregate type to value_struct_elt_for_address");
  1146.  
  1147.   baseclass = t;
  1148.  
  1149.   while (t)
  1150.     {
  1151.       for (i = TYPE_NFIELDS (t) - 1; i >= 0; i--)
  1152.     {
  1153.       char *t_field_name = TYPE_FIELD_NAME (t, i);
  1154.       if (t_field_name && !strcmp (t_field_name, name))
  1155.         {
  1156.           if (TYPE_FIELD_PACKED (t, i))
  1157.         error ("pointers to bitfield members not allowed");
  1158.  
  1159.           v = value_from_long (builtin_type_int,
  1160.                    (LONGEST) (TYPE_FIELD_BITPOS (t, i) >> 3));
  1161.           VALUE_TYPE (v) = lookup_pointer_type (
  1162.               lookup_member_type (TYPE_FIELD_TYPE (t, i), baseclass));
  1163.           return v;
  1164.         }
  1165.     }
  1166.  
  1167.       if (TYPE_N_BASECLASSES (t) == 0)
  1168.     break;
  1169.  
  1170.       t = TYPE_BASECLASS (t, 1);
  1171.     }
  1172.  
  1173.   /* C++: If it was not found as a data field, then try to
  1174.      return it as a pointer to a method.  */
  1175.   t = baseclass;
  1176.  
  1177.   /* Destructors are a special case.  */
  1178.   if (destructor_name_p (name, t))
  1179.     {
  1180.       error ("pointers to destructors not implemented yet");
  1181.     }
  1182.  
  1183.   /* Perform all necessary dereferencing.  */
  1184.   while (intype && TYPE_CODE (intype) == TYPE_CODE_PTR)
  1185.     intype = TYPE_TARGET_TYPE (intype);
  1186.  
  1187.   while (t)
  1188.     {
  1189.       for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; --i)
  1190.     {
  1191.       if (!strcmp (TYPE_FN_FIELDLIST_NAME (t, i), name))
  1192.         {
  1193.           int j = TYPE_FN_FIELDLIST_LENGTH (t, i);
  1194.           struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
  1195.  
  1196.           if (intype == 0 && j > 1)
  1197.         error ("non-unique member `%s' requires type instantiation", name);
  1198.           if (intype)
  1199.         {
  1200.           while (j--)
  1201.             if (TYPE_FN_FIELD_TYPE (f, j) == intype)
  1202.               break;
  1203.           if (j < 0)
  1204.             error ("no member function matches that type instantiation");
  1205.         }
  1206.           else
  1207.         j = 0;
  1208.  
  1209.           if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
  1210.         {
  1211.           v = value_from_long (builtin_type_long,
  1212.                        (LONGEST) TYPE_FN_FIELD_VOFFSET (f, j));
  1213.         }
  1214.           else
  1215.         {
  1216.           struct symbol *s = lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, j),
  1217.                             0, VAR_NAMESPACE, 0);
  1218.           v = locate_var_value (s, 0);
  1219.         }
  1220.           VALUE_TYPE (v) = lookup_pointer_type (lookup_member_type (TYPE_FN_FIELD_TYPE (f, j), baseclass));
  1221.           return v;
  1222.         }
  1223.     }
  1224.  
  1225.       if (TYPE_N_BASECLASSES (t) == 0)
  1226.     break;
  1227.  
  1228.       t = TYPE_BASECLASS (t, 1);
  1229.     }
  1230.   return 0;
  1231. }
  1232.  
  1233. /* Compare two argument lists and return the position in which they differ,
  1234.    or zero if equal.
  1235.  
  1236.    STATICP is nonzero if the T1 argument list came from a
  1237.    static member function.
  1238.  
  1239.    For non-static member functions, we ignore the first argument,
  1240.    which is the type of the instance variable.  This is because we want
  1241.    to handle calls with objects from derived classes.  This is not
  1242.    entirely correct: we should actually check to make sure that a
  1243.    requested operation is type secure, shouldn't we?  */
  1244.  
  1245. int
  1246. typecmp (staticp, t1, t2)
  1247.      int staticp;
  1248.      struct type *t1[];
  1249.      value t2[];
  1250. {
  1251.   int i;
  1252.  
  1253.   if (staticp && t1 == 0)
  1254.     return t2[1] != 0;
  1255.   if (t1 == 0)
  1256.     return 1;
  1257.   if (t1[0]->code == TYPE_CODE_VOID) return 0;
  1258.   if (t1[!staticp] == 0) return 0;
  1259.   for (i = !staticp; t1[i] && t1[i]->code != TYPE_CODE_VOID; i++)
  1260.     {
  1261.       if (! t2[i]
  1262.       || t1[i]->code != t2[i]->type->code
  1263.       || t1[i]->target_type != t2[i]->type->target_type)
  1264.     return i+1;
  1265.     }
  1266.   if (!t1[i]) return 0;
  1267.   return t2[i] ? i+1 : 0;
  1268. }
  1269.  
  1270. /* C++: return the value of the class instance variable, if one exists.
  1271.    Flag COMPLAIN signals an error if the request is made in an
  1272.    inappropriate context.  */
  1273. value
  1274. value_of_this (complain)
  1275.      int complain;
  1276. {
  1277.   extern FRAME selected_frame;
  1278.   struct symbol *func, *sym;
  1279.   char *funname = 0;
  1280.   struct block *b;
  1281.   int i;
  1282.  
  1283.   if (selected_frame == 0)
  1284.     if (complain)
  1285.       error ("no frame selected");
  1286.     else return 0;
  1287.  
  1288.   func = get_frame_function (selected_frame);
  1289.   if (func)
  1290.     funname = SYMBOL_NAME (func);
  1291.   else
  1292.     if (complain)
  1293.       error ("no `this' in nameless context");
  1294.     else return 0;
  1295.  
  1296.   b = SYMBOL_BLOCK_VALUE (func);
  1297.   i = BLOCK_NSYMS (b);
  1298.   if (i <= 0)
  1299.     if (complain)
  1300.       error ("no args, no `this'");
  1301.     else return 0;
  1302.  
  1303.   sym = BLOCK_SYM (b, 0);
  1304.   if (strncmp ("$this", SYMBOL_NAME (sym), 5))
  1305.     if (complain)
  1306.       error ("current stack frame not in method");
  1307.     else return 0;
  1308.  
  1309.   return read_var_value (sym, selected_frame);
  1310. }
  1311. @
  1312.  
  1313.  
  1314. 1.2
  1315. log
  1316. @Changes for Sprite. (Mike checking in for Bob.)
  1317. @
  1318. text
  1319. @d680 3
  1320. d705 1
  1321. @
  1322.  
  1323.  
  1324. 1.1
  1325. log
  1326. @Initial revision
  1327. @
  1328. text
  1329. @d534 1
  1330. d552 1
  1331. d591 20
  1332. @
  1333.